import { defineStore } from 'pinia';
import { getToken, getOpenid, clearNursesAuthStorage } from './helpers';
import { localStg } from '@/utils';
interface NursesState {
  /** 用户信息 */
  nurseNurses: NurseNurses.NurseNurses;
  /** 用户token */
  token: string;

  openid: string;

}

export const useNursesStore = defineStore('nurses-store', {
  state: (): NursesState => ({
    nurseNurses: {
      id: '',
      name: '',
      phone: '',
      sex: '',
      openid: '',
      avatar: ''
    },
    token: getToken(),
    openid: getOpenid(),
  }),
  getters: {
    /** 是否登录 */
    isLogin: state => Boolean(state.token),
    // getNurseUser: (state) => () => state.nurseUser
  },
  actions: {
    setNurseNurses(nurseNurses: NurseNurses.NurseNurses) {
      this.nurseNurses = nurseNurses;
      localStg.set("nurseNurses", nurseNurses)
    },
    setToken(token: string) {
      this.token = token;
      localStg.set("token", token)
    },
    setOpenid(openid: string) {
      this.openid = openid;
      localStg.set("nurse_openid", openid)
    },

    /** 重置auth状态 */
    resetNursesAuthStore() {
      clearNursesAuthStorage();
      this.$reset();
    }
  }
});
